﻿using System;
using System.Data.SqlClient;
using Devv.Core.UniDataTier;
using Yglu.BusinessLayer.Entities;

namespace Yglu.BusinessLayer
{
	public partial class DataAccess
	{
		#region Get

		public static SqlDataReader Store_Get()
		{
			DataHandler db = new DataHandler();

			return (SqlDataReader)db.ExecuteReader("upStore_Get");
		}

		public static SqlDataReader Store_Get(Int32 id)
		{
			DataHandler db = new DataHandler();

			db.AddParameter("@StoreId", id);

			return (SqlDataReader)db.ExecuteReader("upStore_Get");
		}

		#endregion

		#region Insert and update

		public static void Store_Upsert(Store store)
		{
			using (DataHandler db = new DataHandler())
			{
				db.AddParameter("@Title", store.Title);
				db.AddParameter("@Location", store.Location);
				db.AddParameter("@Active", store.Active);

				if (store.Id > 0)
				{
					db.AddParameter("@StoreId", store.Id);
					db.ExecuteScalar("upStore_Update");
				}
				else
				{
					store.Id = Convert.ToInt32(db.ExecuteScalar("upStore_Insert"));
				}
			}
		}

		#endregion
	}
}